package com.pattern.singleton.lazy;

/**
 * 懒汉 内部类的方式加载
 */
public class LazyInnerSingleton {
    private LazyInnerSingleton(){
        if(InnerLazy.LAZY !=null){
            throw new RuntimeException("已存在该实例，不允许有多个");
        }
    }
    // 该方法添加final确保这个方法不会被重写、重载
    public static final LazyInnerSingleton getInstance(){
        return InnerLazy.LAZY;
    }
    private static class InnerLazy{
        private static final LazyInnerSingleton LAZY=new LazyInnerSingleton();
    }
}
